package com.longxi.tianjintianbao.ui.adapter.multitype;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.listener.SearchListener;
import com.longxi.tianjintianbao.model.Search;
import com.longxi.tianjintianbao.widget.SearchView;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class SearchViewBinder extends ItemViewBinder<Search, SearchViewBinder.ViewHolder> {

    SearchListener listener;

    public SearchViewBinder(SearchListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_search, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull Search search) {
        holder.mTvSearchName.setText(search.getName());
        holder.mLlSearchBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onSearch("");
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mLlSearchBtn;
        TextView mTvSearchName;
        ViewHolder(View itemView) {
            super(itemView);
            mLlSearchBtn = itemView.findViewById(R.id.llSearchBtn);
            mTvSearchName = itemView.findViewById(R.id.tvSearchName);
        }
    }
}
